package com.fhz.high5kotlin.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.fhz.high5kotlin.User

/**
 * 时间:2023/3/23
 * @author Mr.Feng
 * 简述: viewModel
 * 缓存页面的数据
 *
 */
class MyViewModel(var a:Int): ViewModel(){

    var num = a  //初始值

    private var age:MutableLiveData<Int> = MutableLiveData()
    val ageVal: LiveData<Int>
    get() = age
    fun updateAge(a :Int){
        age.value = a
    }

    private var car:MutableLiveData<Car> = MutableLiveData()
    val carVal: LiveData<Int>
    get() = Transformations.map(car){
        it.price
    }

    fun updateCar(c : Car){
        car.value = c
    }





    fun add(){
        num++
    }
}